package com.itheima.sort;

public class A01_BubbleSort {
    public static void main(String[] args) {
        int[] arr = {2, 5, 1, 4, 3};
        //外层循环代表执行的轮数（n个元素最多执行n-1轮）
        for (int i = 0; i < arr.length - 1; i++) {
            //内层循环代表每一轮比较的次数
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = 0;
                    temp = arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                }
            }

        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }
}
